package org.dean.webapps.projectname.presentation.controller;

import org.dean.webapps.projectname.common.State;
import net.sf.json.JSONArray;
import org.dean.webapps.projectname.constants.VelocityConstants;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: v_yina01
 * Date: 9/15/11
 * Time: 4:03 PM
 * To change this template use File | Settings | File Templates.
 */
@Controller
public class CommonController implements Serializable {

    @RequestMapping(value = "/common/ajax/load_state",
            method = {RequestMethod.POST, RequestMethod.GET})
    public String loadState(HttpServletRequest request,
                                       HttpServletResponse response,
                                       ModelMap model) {

        List<String> stateList = State.getStates();

        JSONArray outPaths = JSONArray.fromObject(stateList);
        model.addAttribute(VelocityConstants.JSON_DATA, outPaths.toString());

        return "/common/ajax_json_data";
    }
}
